Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TosaToLinalg: Fix unsigned tosa.clamp #155

Merged
merged 2 commits into from
Apr 12, 2024

Conversation

mgehre-amd
Copy link
Collaborator

Lowering tosa.clamp with unsigned integer element types needs to use cmpi ult instead of cmpi slt,
and the lower/upper bound must be interpreted as unsigned when converting to to arith.constants.

@mgehre-amd mgehre-amd requested a review from TinaAMD April 8, 2024 10:51
Copy link

github-actions bot commented Apr 8, 2024

:white_check_mark: With the latest revision this PR passed the C/C++ code formatter.

@mgehre-amd mgehre-amd force-pushed the matthias.TosaToLinalg_unsigned_clamp branch from 8b524da to 00dc051 Compare April 8, 2024 21:28
@cferry-AMD
Copy link
Collaborator

We should add a failing test with ui64:

  %failure = tosa.clamp %arg1 {min_int = -1 : i64, max_int = 5 : i64, min_fp = 1.0 : f32, max_fp = 5.0 : f32} : (tensor<1xui64>) -> tensor<1xui64>

Such a test will be useful to point out there is a hardcoded 63-bit limit in this pass, to be dealt with whenever larger integer support comes in.

Copy link
Collaborator

@cferry-AMD cferry-AMD left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good!

mlir/lib/Conversion/TosaToLinalg/TosaToLinalg.cpp Outdated Show resolved Hide resolved
Copy link

@TinaAMD TinaAMD left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

One conceptual issue with clamp in general which we could think about fixing:
The tosa spec defines that the input+output type as well as the type of the attributes (min/max) need to be the same. It would be neat to enforce this (table gen + verifier), as it would prevent people from writing clip ranges which do not make sense for the given data type (as the case tested here, with unsigned inputs and a -1 lower bound).

@mgehre-amd
Copy link
Collaborator Author

We should add a failing test with ui64:

  %failure = tosa.clamp %arg1 {min_int = -1 : i64, max_int = 5 : i64, min_fp = 1.0 : f32, max_fp = 5.0 : f32} : (tensor<1xui64>) -> tensor<1xui64>

Such a test will be useful to point out there is a hardcoded 63-bit limit in this pass, to be dealt with whenever larger integer support comes in.

Thanks! I add such test now.

@mgehre-amd mgehre-amd enabled auto-merge April 12, 2024 14:41
@mgehre-amd mgehre-amd merged commit dfa02b1 into feature/fused-ops Apr 12, 2024
4 checks passed
@mgehre-amd mgehre-amd deleted the matthias.TosaToLinalg_unsigned_clamp branch April 12, 2024 15:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants